//
//  ShareManager.m
//  Cat
//
//  Created by lushitong on 2018/12/18.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#define kShareKey @"5c128160b465f572e7000181"

#import <UMCommon/UMCommon.h>
#import <UMShare/UMShare.h>
#import <UserNotifications/UserNotifications.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import "ShareManager.h"
#import <UMAnalytics/MobClick.h>

@implementation ShareManager

+ (void)initUMShareConfig {
	[[UMSocialManager defaultManager] openLog:YES];
	[UMConfigure initWithAppkey:kShareKey channel:@"App Store"];
	[MobClick setScenarioType:E_UM_DPLUS];
	
	[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx308ace688120602b" appSecret:@"2386142c72d272cfefceecc39adc6349" redirectURL:@"http://mobile.umeng.com/social"];
	[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatTimeLine appKey:@"wx308ace688120602b" appSecret:@"2386142c72d272cfefceecc39adc6349" redirectURL:@"http://mobile.umeng.com/social"];
	[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"101531480" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
	
}

+ (void)showShareViewWithUrl:(NSString *)url title:(NSString *)title description:(NSString *)description imageUrl:(NSString *)imageUrl {
	
}

+ (void)shareUrl:(NSString *)url text:(NSString *)text description:(NSString *)description imageUrl:(NSString *)imageUrl shareType:(ShareType)shareType {
	
}

+ (void)shareTextWithString:(NSString *)text platformType:(UMSocialPlatformType)platformType andWith:(UIViewController *)viewCrl {
	//创建分享消息对象
	UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
	//设置文本
	messageObject.text = text;
	
	//调用分享接口
	[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:viewCrl completion:^(id data, NSError *error) {
		if (error) {
			NSLog(@"************Share fail with error %@*********",error);
		}else{
			NSLog(@"response data is %@",data);
		}
	}];
}


+ (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType andWith:(UIViewController *)viewCrl {
	//创建分享消息对象
	UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
	
	//创建网页内容对象
	NSString* thumbURL =  @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
	UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享的东西" descr:@"描述" thumImage:thumbURL];
	//设置网页地址
	shareObject.webpageUrl = @"http://mobile.umeng.com/social";
	
	//分享消息对象设置分享内容对象
	messageObject.shareObject = shareObject;
	
	//调用分享接口
	[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:viewCrl completion:^(id data, NSError *error) {
		if (error) {
			UMSocialLogInfo(@"************Share fail with error %@*********",error);
		}else{
			if ([data isKindOfClass:[UMSocialShareResponse class]]) {
				UMSocialShareResponse *resp = data;
				//分享结果消息
				UMSocialLogInfo(@"response message is %@",resp.message);
				//第三方原始返回的数据
				UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
				
			}else{
				UMSocialLogInfo(@"response data is %@",data);
			}
		}
	}];
}
+ (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType withShareUrL:(NSString *)shareURL andWith:(UIViewController *)viewCrl {
	//创建分享消息对象
	UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
	
	UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"您的好友邀请您加入喵象" descr:@"领券再淘宝，优惠高达50%，赚赚赚" thumImage:[UIImage imageNamed:@"app_icon"]];
	//设置网页地址
	shareObject.webpageUrl = shareURL;
	
	//分享消息对象设置分享内容对象
	messageObject.shareObject = shareObject;
	
	//调用分享接口
	[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:viewCrl completion:^(id data, NSError *error) {
		if (error) {
			UMSocialLogInfo(@"************Share fail with error %@*********",error);
		}else{
			if ([data isKindOfClass:[UMSocialShareResponse class]]) {
				UMSocialShareResponse *resp = data;
				//分享结果消息
				UMSocialLogInfo(@"response message is %@",resp.message);
				//第三方原始返回的数据
				UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
				
			}else{
				UMSocialLogInfo(@"response data is %@",data);
			}
		}
	}];
}

+ (BOOL)isInstallHaveQQ {
	return [QQApiInterface isQQInstalled];
}

@end
